package sdc.com.petscalendar.fragments;

import sdc.com.petscalendar.R;
import sdc.com.petscalendar.objects.Treament;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

public class TreamentDetailFragment extends BaseFragment implements
		View.OnClickListener {
	private ImageView mIvProduct;
	private TextView mTreatmentName, mTvTreatmentDescription, mTvProductname;
	private Button mBtnReturn;
	private Treament mTreament;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		if (mView == null) {
			mView = inflater.inflate(R.layout.fragment_treament_details,
					container, false);
		}
		return mView;
	}

	@Override
	public void onViewCreated(View view, Bundle savedInstanceState) {
		super.onViewCreated(view, savedInstanceState);
		initComponents();
		addListeners();
	}

	private void initComponents() {
		mTreatmentName = (TextView) getView().findViewById(
				R.id.tv_treament_name);
		mTvTreatmentDescription = (TextView) getView().findViewById(
				R.id.tv_treament_description);
		mTvProductname = (TextView) getView()
				.findViewById(R.id.tv_product_name);
		mIvProduct = (ImageView) getView().findViewById(R.id.iv_product_image);
		mBtnReturn = (Button) getView().findViewById(R.id.btn_return);

		if (mTreament != null) {
			mTvTreatmentDescription.setText(mTreament.getDescription());
			mTreatmentName.setText(mTreament.getName());
			mTvProductname.setText(mTreament.getProduct().getName());
			if (mTreament.getProduct().getImage() != null
					&& mTreament.getProduct().getImage().length() > 0) {
				Bitmap bm = BitmapFactory.decodeFile(mTreament.getProduct()
						.getImage());
				mIvProduct.setImageBitmap(bm);
			}
		}
	}

	private void addListeners() {
		mBtnReturn.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.btn_return:
			getActivity().onBackPressed();
			break;
		default:
			break;
		}

	}

	public void setTreament(Treament treament) {
		mTreament = treament;
	}
}
